package com.hiv.controller.wechat;

import com.hiv.common.BaseController;
import com.hiv.common.PageInfo;
import com.hiv.common.WebResponse;
import com.hiv.common.param.page.PageQueryBarCodeParam;
import com.hiv.mapper.domain.Admin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.hiv.mapper.domain.BarCode;
import com.hiv.service.BarCodeService;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhanghong
 * @version XcxBarCodeController.java, v 0.1 2022-09-20 XcxBarCodeController Exp $$
 */
@RestController
@RequestMapping("/wechat/barCode")
@Api(value = "条码模块", tags = {"【小程序端】条码模块"})
public class XcxBarCodeController extends BaseController {
    @Autowired
    private BarCodeService barCodeService;

    @ApiOperation(value = "分页查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<BarCode>> pageQuery(HttpServletRequest request, @RequestBody PageQueryBarCodeParam param) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(barCodeService.pageQuery(param));
    }

    @ApiOperation(value = "根据id查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<BarCode> getById(HttpServletRequest request, @PathVariable("id") long id) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(barCodeService.getById(id));
    }

    @ApiOperation(value = "根据code查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/getByCode/{code}")
    public WebResponse<BarCode> getByCode(HttpServletRequest request, @PathVariable("code") String code) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(barCodeService.getByCode(code));
    }

    @ApiOperation(value = "保存", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/save")
    public WebResponse<Boolean> save(HttpServletRequest request, @RequestBody BarCode param) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(barCodeService.save(param));
    }

    @ApiOperation(value = "删除", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/delete")
    public WebResponse<Boolean> delete(HttpServletRequest request, @RequestParam String ids) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(barCodeService.deleteByIds(ids));
    }
}
